#include "../logs/mylog.h"
#include <unistd.h>

using std::cout;
using std::endl;

void test_log(const string &name)
{
    INFO("%s","测试开始");
    mylog::Logger::ptr logger = mylog::LoggerManager::getInstance().getLogger(name);
    logger->debug("%s","测试日志");
    logger->info("%s","测试日志");
    logger->warn("%s","测试日志");
    logger->error("%s","测试日志");
    logger->fatal("%s","测试日志");
    INFO("%s","测试结束");
}

int main()
{
    std::unique_ptr<mylog::LoggerBuilder> builder(new mylog::GlobalLoggerBuilder());
    builder->buildLoggerName("sync_logger");
    builder->buildLoggerLevel(mylog::LogLevel::level::DEBUG);
    builder->buildLoggerType(mylog::LoggerType::LOGGER_SYNC);
    builder->buildFormatter("[%c][%p][%f:%l]%m%n");
    builder->buildSink<mylog::StdoutSink>();
    builder->buildSink<mylog::FileSink>("./logfile/async.log");
    builder->buildSink<mylog::RollBySizeSink>("./logfile/sync-roll-by-size", 1024 * 1024);
    builder->buildSink<mylog::RollByTimeSink>("./logfile/sync-roll-by-time", mylog::TimeGap::GAP_SECOND);
    mylog::Logger::ptr logger = builder->build();
    test_log("sync_logger");

    time_t old=mylog::Util::Date::now();
    while(mylog::Util::Date::now() < old + 5)
    {
        logger->fatal("这是一条测试日志");
        usleep(1000);
    }
    return 0;
}